from pages.base_page import BasePage
from selenium.webdriver.common.by import By


class BusinessHomePage(BasePage):
    url = '/crm/index.php?m=business'
    #定位器
    add_new_business_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div > a')
    business_name_locator = (By.ID,'name')
    estimate_price_locator = (By.ID,'estimate_price')
    customer_name_locator = (By.ID,'customer_name')
    fields_locator = (By.ID,'fields')
    searchs_locator = (By.ID,'searchs')
    searchs_btn_locator = (By.CSS_SELECTOR,'#dialog-message > div > ul > li:nth-child(4) > button')
    first_customer_name_locator = (By.XPATH,'/html/body/div[10]/div[2]/table/tbody[2]/tr[1]/td[1]/input[1]')
    sure_button = (By.CSS_SELECTOR,'body > div:nth-child(17) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span')
    save_button = (By.XPATH,'/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td/input[1]')
    save_success_locator = (By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    save_error_locator = (By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    first_business_view_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[11]/a[1]')
    first_business_edit_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[11]/a[3]')
    delete_business_locator = (By.XPATH,'/html/body/div[5]/div[3]/div[2]/form/table/tbody/tr[1]/td[1]/input')
    delete_business_btn_locator = (By.ID,'delete')
    #点击新建商机
    def click_new_business(self):
        self.driver.find_element(*self.add_new_business_locator).click()
    #输入商机名称
    def input_business_name(self,business_name):
        self.driver.find_element(*self.business_name_locator).send_keys(business_name)
    #输入预计成交价
    def input_estimate_price(self,estimate_price):
        self.driver.find_element(*self.estimate_price_locator).send_keys(estimate_price)
    #点击客户名称
    def click_customer_name(self):
        self.driver.find_element(*self.customer_name_locator).click()
    #返回查询条件元素，方便调用下拉框操作
    def click_fields(self):
        return self.driver.find_element(*self.fields_locator)
    #在搜索框输入客户名称
    def click_searchs(self,customer_name):
        self.driver.find_element(*self.searchs_locator).send_keys(customer_name)
    #点击搜索按钮
    def click_searchs_button(self):
        self.driver.find_element(*self.searchs_btn_locator).click()
    #点击选择第一个客户
    def check_first_customer_name(self):
        self.driver.find_element(*self.first_customer_name_locator).click()
    #点击选择客户界面的确定按钮
    def click_sure_button(self):
        self.driver.find_element(*self.sure_button).click()
    #点击保存按钮
    def click_save_button(self):
        self.driver.find_element(*self.save_button).click()
    #返回保存成功的提示信息
    def save_success(self):
        return self.driver.find_element(*self.save_success_locator).text

    #返回保存失败的提示信息
    def save_error_info(self):
        return self.driver.find_element(*self.save_error_locator).text
    #点击商机详情
    def enter_business_view_page(self):
        self.driver.find_element(*self.first_business_view_locator).click()
    #点击商机编辑
    def enter_business_edit_page(self):
        self.driver.find_element(*self.first_business_edit_locator).click()

    def delete_business(self):
        self.driver.find_element(*self.delete_business_locator).click()
    def delete_business_btn(self):
        self.driver.find_element(*self.delete_business_btn_locator).click()











